/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * AsignacionCursoUnidad.java
 *
 * Created on 16/07/2012, 06:15:45 AM
 */

package interfaz;

import Clases.Catedratico;
import Clases.Catedraticocurso;
import Clases.Ciclocurso;
import Clases.Curso;
import Clases.Cursounidad;
import Clases.Unidad;
import Controladores.CatedraticoJpaController;
import Controladores.CatedraticocursoJpaController;
import Controladores.CiclocursoJpaController;
import Controladores.CursoJpaController;
import Controladores.CursounidadJpaController;
import Controladores.UnidadJpaController;
import escuela.conexion;
import escuela.exceptions.PreexistingEntityException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author DeLeon
 */
public class AsignacionCursoUnidad extends javax.swing.JDialog {

    conexion cnx = conexion.ObtenerInstancia();
    EntityManagerFactory emf = cnx.ObtenerEMF();
    EntityManager em = emf.createEntityManager();
    CursounidadJpaController _curuni = new CursounidadJpaController(emf);
    Cursounidad actual, seleccionado;
    Mensajes msj = new Mensajes(this);
    UnidadJpaController _unidades = new UnidadJpaController(emf);
    CatedraticoJpaController _catedraticos = new CatedraticoJpaController(emf);
    CursoJpaController _cursos = new CursoJpaController(emf);
    ArrayList idClases= new ArrayList();
    CiclocursoJpaController _ciclos = new CiclocursoJpaController(emf);

    /** Creates new form AsignacionCursos */

    private void CargarTabla()
    {
        Object[] datos= new Object[5];
        DefaultTableModel modelo = new DefaultTableModel();
        modelo.addColumn("Id");
        modelo.addColumn("Unidad");
        modelo.addColumn("Catedratico Apellido");
        modelo.addColumn("Catedratico Nombre");
        modelo.addColumn("Curso");
        List<Cursounidad> listacurso = this._curuni.findCursounidadEntities();
            for(Cursounidad i: listacurso)
            {
                datos[0]=i.getIdCursoUnidad();
                datos[1]=i.getUnidad().getNombre();
                datos[2]=i.getCatedraticocurso().getCatedratico().getApellidos();
                datos[3]=i.getCatedraticocurso().getCatedratico().getNombres();
                datos[4]=i.getCatedraticocurso().getCurso().getNombre()+" ("+i.getCatedraticocurso().getCiclocurso().getAño()+")";
                modelo.addRow(datos);
            }
        this.jTable1.setModel(modelo);
    }

    private void CargarCombos(){
        List<Unidad> claseL = _unidades.findUnidadEntities();
        for(Unidad cu: claseL){
            this.clasec.addItem(cu.getNombre());
            this.clasee.addItem(cu.getNombre());
        }

        List<Catedratico> catedraticoL = _catedraticos.findCatedraticoEntities();
        for(Catedratico cu: catedraticoL){
            this.catedraticoc.addItem(cu.getNombres()+" "+cu.getApellidos());
            this.catedraticoe.addItem(cu.getNombres()+" "+cu.getApellidos());
        }

        List<Curso> cursoL = _cursos.findCursoEntities();
        for(Curso cu: cursoL){
            this.cursoc.addItem(cu.getNombre());
            this.cursoe.addItem(cu.getNombre());
        }

        List<Ciclocurso> ciclocursoL = _ciclos.findCiclocursoEntities();
        for(Ciclocurso cu: ciclocursoL){
            this.añoc.addItem(cu.getAño());
            this.añoe.addItem(cu.getAño());
        }

    }

    private void IngresarCurso()
    {
        if(this.clasec.getSelectedIndex()!=-1 && this.catedraticoc.getSelectedIndex()!=-1 && this.cursoc.getSelectedIndex()!=-1 && this.añoc.getSelectedIndex()!=-1)
        {            
            Catedratico idcate = this._catedraticos.findCatedratico(Short.valueOf(String.valueOf(this.catedraticoc.getSelectedIndex()+1)));
            Curso idcurso = this._cursos.findCurso(Short.parseShort(String.valueOf(this.cursoc.getSelectedIndex()+1)));
            Unidad idunidad= this._unidades.findUnidad(Short.parseShort(String.valueOf(this.clasec.getSelectedIndex()+1)));
            Ciclocurso idciclo = this._ciclos.findCiclocurso(Short.parseShort(String.valueOf(this.añoc.getSelectedIndex()+1)));
            Cursounidad  nuevo = new Cursounidad(this._curuni.GenerarId());
            nuevo.setUnidad(idunidad);
            Catedraticocurso cc=null;
            CatedraticocursoJpaController cjpa= new CatedraticocursoJpaController(emf);
            List<Catedraticocurso> ccl = cjpa.findCatedraticocursoEntities();
            for(Catedraticocurso ccind:ccl)
            {
                if(ccind.getCatedratico().equals(idcate) && ccind.getCurso().equals(idcurso) && ccind.getCiclocurso().equals(idciclo) )
                {
                    cc=ccind;
                    break;
                }
            }
            nuevo.setCatedraticocurso(cc);
            try {
                this._curuni.create(nuevo);
            } catch (PreexistingEntityException ex) {
                Logger.getLogger(AsignacionCursoUnidad.class.getName()).log(Level.SEVERE, null, ex);
            } catch (Exception ex) {
                Logger.getLogger(AsignacionCursoUnidad.class.getName()).log(Level.SEVERE, null, ex);
            }
            JOptionPane.showMessageDialog(null, "Se ha asignado el curso Correctamente");
        }
        else
        {
            JOptionPane.showMessageDialog(null, "Falta seleccionar mas datos");
        }
    }

    private void ModificarCurso()
    {
        int filaseleccionada = this.jTable1.getSelectedRow();
        if(filaseleccionada > -1)
        {
            try
            {
                if(this.clasec.getSelectedIndex()!=-1 && this.catedraticoc.getSelectedIndex()!=-1 && this.cursoc.getSelectedIndex()!=-1 && this.añoc.getSelectedIndex()!=-1)
                {
                    Short idCatCurso= (Short) this.jTable1.getValueAt(filaseleccionada,0);
                    actual=this._curuni.findCursounidad(idCatCurso);
                    Catedratico idcate = this._catedraticos.findCatedratico(Short.valueOf(String.valueOf(this.catedraticoe.getSelectedIndex()+1)));
                    Curso idcurso = this._cursos.findCurso(Short.parseShort(String.valueOf(this.cursoe.getSelectedIndex()+1)));
                    Unidad idunidad= this._unidades.findUnidad(Short.parseShort(String.valueOf(this.clasee.getSelectedIndex()+1)));
                    Ciclocurso idciclo = this._ciclos.findCiclocurso(Short.parseShort(String.valueOf(this.añoe.getSelectedIndex()+1)));
                    actual.setUnidad(idunidad);
                    Catedraticocurso cc=null;
                    CatedraticocursoJpaController cjpa= new CatedraticocursoJpaController(emf);
                    List<Catedraticocurso> ccl = cjpa.findCatedraticocursoEntities();
                    for(Catedraticocurso ccind:ccl)
                    {
                        if(ccind.getCatedratico().equals(idcate) && ccind.getCurso().equals(idcurso) && ccind.getCiclocurso().equals(idciclo) )
                        {
                            cc=ccind;
                            break;
                        }
                    }
                    actual.setCatedraticocurso(cc);
                    try {
                        this._curuni.edit(actual);
                    } catch (Exception ex) {
                        Logger.getLogger(AdminCurso.class.getName()).log(Level.SEVERE, null, ex);
                    }
                    JOptionPane.showMessageDialog(null, "Se ha modificado Correctamente la asignacion");
                }
                else
                {
                    JOptionPane.showMessageDialog(null, "Faltan datos por seleccionar");
                }
            }
            catch (Exception ex) {
                    Logger.getLogger(AdminCurso.class.getName()).log(Level.SEVERE, null, ex);
                }
        }
        else
        {
            JOptionPane.showMessageDialog(null, "Seleccione Fila");
        }
    }

    private void Aceptar(){
        int selec = this.Pestaña.getSelectedIndex();
        switch(selec){
            case 0:
                    IngresarCurso();
                    break;
            case 1:
                    ModificarCurso();
                    break;
        }
        this.CargarTabla();
    }

    private void Cancelar(){
        int selec = this.Pestaña.getSelectedIndex();
        byte respuesta;
        switch(selec){
            case 0: respuesta =msj.MensajeConfirmacion("¿Esta seguro que quiere cancelar el ingreso? Todos los datos se perderan");
                    switch(respuesta){
                        case 0:
                            this.clasec.setSelectedIndex(-1);
                            this.catedraticoc.setSelectedIndex(-1);
                            this.cursoc.setSelectedIndex(-1);
                            this.añoc.setSelectedIndex(-1);
                            break;
                    }
                    break;
            case 1: respuesta = msj.MensajeConfirmacion("¿Esta seguro que desea cancelar la actualizacion? Todos los datos que no esten guardados se perderan");
                    switch(respuesta){
                        case 0:
                            this.clasec.setSelectedIndex(-1);
                            this.catedraticoc.setSelectedIndex(-1);
                            this.cursoc.setSelectedIndex(-1);
                            this.añoc.setSelectedIndex(-1);
                            break;
                    }
                    break;
        }
    }
    public AsignacionCursoUnidad(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        this.setLocationRelativeTo(null);
        CargarCombos();
        this.CargarTabla();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTaskPane1 = new com.l2fprod.common.swing.JTaskPane();
        jLabel1 = new javax.swing.JLabel();
        informacion = new javax.swing.JLabel();
        cancelar = new javax.swing.JButton();
        aceptar = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        Pestaña = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        jLabel12 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        clasec = new javax.swing.JComboBox();
        catedraticoc = new javax.swing.JComboBox();
        jLabel13 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        cursoc = new javax.swing.JComboBox();
        jLabel15 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        añoc = new javax.swing.JComboBox();
        jLabel14 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        catedraticoe = new javax.swing.JComboBox();
        clasee = new javax.swing.JComboBox();
        jLabel6 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        cursoe = new javax.swing.JComboBox();
        jLabel10 = new javax.swing.JLabel();
        añoe = new javax.swing.JComboBox();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Asignación Notas-Unidades-Curso");

        jLabel1.setFont(new java.awt.Font("Arial", 1, 14));
        jLabel1.setForeground(new java.awt.Color(255, 255, 255));
        jLabel1.setText("Asignacion de Notas-Unidades al Curso");
        jTaskPane1.add(jLabel1);

        informacion.setForeground(new java.awt.Color(255, 255, 255));
        informacion.setText("jLabel2");
        jTaskPane1.add(informacion);

        cancelar.setText("Cancelar");
        cancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelarActionPerformed(evt);
            }
        });
        cancelar.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                cancelarKeyPressed(evt);
            }
        });

        aceptar.setText("Aceptar");
        aceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                aceptarActionPerformed(evt);
            }
        });
        aceptar.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                aceptarKeyPressed(evt);
            }
        });

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Id", "Nombre"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Short.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jTable1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTable1MouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(jTable1);

        Pestaña.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                PestañaStateChanged(evt);
            }
        });
        Pestaña.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                PestañaFocusGained(evt);
            }
        });

        jLabel12.setForeground(new java.awt.Color(255, 0, 0));
        jLabel12.setText("*");
        jLabel12.setToolTipText("Campo Obligatorio");

        jLabel3.setFont(new java.awt.Font("Arial", 0, 12));
        jLabel3.setText("Unidad:");

        jLabel13.setForeground(new java.awt.Color(255, 0, 0));
        jLabel13.setText("*");
        jLabel13.setToolTipText("Campo Obligatorio");

        jLabel5.setFont(new java.awt.Font("Arial", 0, 12));
        jLabel5.setText("Catedratico:");

        jLabel15.setForeground(new java.awt.Color(255, 0, 0));
        jLabel15.setText("*");
        jLabel15.setToolTipText("Campo Obligatorio");

        jLabel7.setFont(new java.awt.Font("Arial", 0, 12));
        jLabel7.setText("Curso:");

        jLabel14.setForeground(new java.awt.Color(255, 0, 0));
        jLabel14.setText("*");
        jLabel14.setToolTipText("Campo Obligatorio");

        jLabel9.setFont(new java.awt.Font("Arial", 0, 12));
        jLabel9.setText("Año:");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addGap(127, 127, 127)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel14, javax.swing.GroupLayout.PREFERRED_SIZE, 6, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel9)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 46, Short.MAX_VALUE)
                        .addComponent(añoc, javax.swing.GroupLayout.PREFERRED_SIZE, 227, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel13, javax.swing.GroupLayout.PREFERRED_SIZE, 6, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(catedraticoc, javax.swing.GroupLayout.PREFERRED_SIZE, 227, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel12, javax.swing.GroupLayout.PREFERRED_SIZE, 6, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 27, Short.MAX_VALUE)
                        .addComponent(clasec, javax.swing.GroupLayout.PREFERRED_SIZE, 227, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel15, javax.swing.GroupLayout.PREFERRED_SIZE, 6, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel7)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 33, Short.MAX_VALUE)
                        .addComponent(cursoc, javax.swing.GroupLayout.PREFERRED_SIZE, 227, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(110, 110, 110))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addGap(25, 25, 25)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, 27, Short.MAX_VALUE)
                        .addComponent(jLabel12, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(clasec, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, 27, Short.MAX_VALUE)
                    .addComponent(jLabel13, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(catedraticoc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel7, javax.swing.GroupLayout.DEFAULT_SIZE, 27, Short.MAX_VALUE)
                        .addComponent(jLabel15, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(cursoc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9, javax.swing.GroupLayout.DEFAULT_SIZE, 27, Short.MAX_VALUE)
                    .addComponent(jLabel14, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(añoc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(21, 21, 21))
        );

        Pestaña.addTab("Crear", jPanel1);

        jLabel4.setFont(new java.awt.Font("Arial", 0, 12));
        jLabel4.setText("Unidad:");

        jLabel6.setFont(new java.awt.Font("Arial", 0, 12));
        jLabel6.setText("Catedratico:");

        jLabel8.setFont(new java.awt.Font("Arial", 0, 12));
        jLabel8.setText("Curso:");

        jLabel10.setFont(new java.awt.Font("Arial", 0, 12));
        jLabel10.setText("Año:");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addGap(119, 119, 119)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel6)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(catedraticoe, javax.swing.GroupLayout.PREFERRED_SIZE, 227, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(12, 12, 12)
                        .addComponent(jLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 27, Short.MAX_VALUE)
                        .addComponent(clasee, javax.swing.GroupLayout.PREFERRED_SIZE, 227, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel2Layout.createSequentialGroup()
                        .addGap(12, 12, 12)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                                .addComponent(jLabel10)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 46, Short.MAX_VALUE)
                                .addComponent(añoe, javax.swing.GroupLayout.PREFERRED_SIZE, 227, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(jLabel8)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 33, Short.MAX_VALUE)
                                .addComponent(cursoe, javax.swing.GroupLayout.PREFERRED_SIZE, 227, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addGap(118, 118, 118))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addGap(46, 46, 46)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, 27, Short.MAX_VALUE)
                    .addComponent(clasee, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6, javax.swing.GroupLayout.DEFAULT_SIZE, 27, Short.MAX_VALUE)
                    .addComponent(catedraticoe, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel8, javax.swing.GroupLayout.DEFAULT_SIZE, 27, Short.MAX_VALUE)
                    .addComponent(cursoe, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(añoe, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel10, javax.swing.GroupLayout.DEFAULT_SIZE, 27, Short.MAX_VALUE))
                .addGap(44, 44, 44))
        );

        Pestaña.addTab("Editar", jPanel2);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jTaskPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 571, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 399, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(cancelar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(aceptar))
                    .addComponent(Pestaña, javax.swing.GroupLayout.DEFAULT_SIZE, 551, Short.MAX_VALUE)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 551, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jTaskPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(Pestaña)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(aceptar)
                    .addComponent(cancelar))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void cancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelarActionPerformed
        // TODO add your handling code here:
        Cancelar();
}//GEN-LAST:event_cancelarActionPerformed

    private void cancelarKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_cancelarKeyPressed
        // TODO add your handling code here:
        if(evt.getKeyCode()==10){
            Cancelar();
        }
}//GEN-LAST:event_cancelarKeyPressed

    private void aceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_aceptarActionPerformed
        // TODO add your handling code here:
        Aceptar();
}//GEN-LAST:event_aceptarActionPerformed

    private void aceptarKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_aceptarKeyPressed
        // TODO add your handling code here:
        if(evt.getKeyCode()==10){
            Aceptar();
        }
}//GEN-LAST:event_aceptarKeyPressed

    private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable1MouseClicked
        // TODO add your handling code here:
        int filaseleccionada = this.jTable1.getSelectedRow();
        if(filaseleccionada > -1) {
            try {
                Short idCurso= (Short) this.jTable1.getValueAt(filaseleccionada,0);
                this.seleccionado=this._curuni.findCursounidad(idCurso);
                this.clasec.setSelectedIndex(this.seleccionado.getIdCursoUnidad());
                this.catedraticoc.setSelectedIndex(this.seleccionado.getCatedraticocurso().getCatedratico().getIdCatedratico());
                this.cursoc.setSelectedIndex(this.seleccionado.getCatedraticocurso().getCurso().getIdCurso());
                this.añoc.setSelectedIndex(this.seleccionado.getCatedraticocurso().getCiclocurso().getIdCicloCurso());
            } catch (Exception ex) {
                Logger.getLogger(AdminCurso.class.getName()).log(Level.SEVERE, null, ex);
            }
        } else {
            JOptionPane.showMessageDialog(null, "Seleccione Fila");
        }
}//GEN-LAST:event_jTable1MouseClicked

    private void PestañaStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_PestañaStateChanged
        // TODO add your handling code here:
        if(this.Pestaña.getSelectedIndex()==1) {
            this.informacion.setText("Seleccione una asignacion de la tabla, para modificarla");
            this.aceptar.setEnabled(true);
            this.cancelar.setEnabled(true);
        } else if(this.Pestaña.getSelectedIndex()==0){
            this.informacion.setText("Creacion de una nueva asignacion, los campos con * son obligatorios");
            this.aceptar.setEnabled(true);
            this.cancelar.setEnabled(true);
        }
}//GEN-LAST:event_PestañaStateChanged

    private void PestañaFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_PestañaFocusGained
        // TODO add your handling code here:
}//GEN-LAST:event_PestañaFocusGained

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                AsignacionCursoUnidad dialog = new AsignacionCursoUnidad(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTabbedPane Pestaña;
    private javax.swing.JButton aceptar;
    private javax.swing.JComboBox añoc;
    private javax.swing.JComboBox añoe;
    private javax.swing.JButton cancelar;
    private javax.swing.JComboBox catedraticoc;
    private javax.swing.JComboBox catedraticoe;
    private javax.swing.JComboBox clasec;
    private javax.swing.JComboBox clasee;
    private javax.swing.JComboBox cursoc;
    private javax.swing.JComboBox cursoe;
    private javax.swing.JLabel informacion;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    private com.l2fprod.common.swing.JTaskPane jTaskPane1;
    // End of variables declaration//GEN-END:variables

}
